package cn.lovemmd.model.admin.config;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * FastJson2配置类
 * 替代Jackson作为JSON处理器
 * 
 * @author TLS
 * @since 2024-01-01
 */
@Configuration
public class FastJsonConfig {

    @Bean
    @Primary
    public void configureFastJson() {
        // 简化配置，只配置基本的序列化特性
        JSON.config(JSONWriter.Feature.WriteMapNullValue);
        JSON.config(JSONWriter.Feature.WriteNullListAsEmpty);
        JSON.config(JSONWriter.Feature.WriteNullStringAsEmpty);
        JSON.config(JSONWriter.Feature.WriteNullNumberAsZero);
        JSON.config(JSONWriter.Feature.WriteNullBooleanAsFalse);
        JSON.config(JSONWriter.Feature.WriteEnumsUsingName);
        JSON.config(JSONWriter.Feature.WriteBigDecimalAsPlain);
    }
}
